package com.ld.poetry.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ld.poetry.aop.LoginCheck;
import com.ld.poetry.config.PoetryResult;
import com.ld.poetry.entity.MenstruationConfig;
import com.ld.poetry.service.MenstruationConfigService;
import com.ld.poetry.vo.BaseRequestVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 家庭信息 前端控制器
 * </p>
 *
 * @author sara
 * @since 2023-01-03
 */
@RestController
@RequestMapping("/menstruationConfig")
public class MenstruationConfigController {

    @Autowired
    private MenstruationConfigService menstruationConfigService;


    /**
     * 保存月经配置
     */
    @LoginCheck(1)
    @PostMapping("/saveMenstruationConfig")
    public PoetryResult saveMenstruationConfig(@Validated @RequestBody MenstruationConfig menstruationConfig) {
        menstruationConfigService.save(menstruationConfig);
        return PoetryResult.success();
    }


    /**
     * 删除月经配置
     */
    @GetMapping("/deleteMenstruationConfig")
    @LoginCheck(1)
    public PoetryResult deleteMenstruationConfig(@RequestParam("id") Integer id) {
        menstruationConfigService.removeById(id);
        return PoetryResult.success();
    }


    /**
     * 更新月经配置
     */
    @PostMapping("/updateMenstruationConfig")
    @LoginCheck(1)
    public PoetryResult updateMenstruationConfig(@Validated @RequestBody MenstruationConfig menstruationConfig) {
        menstruationConfigService.updateById(menstruationConfig);
        return PoetryResult.success();
    }


    /**
     * 查询月经配置List
     */
    @PostMapping("/listMenstruationConfig")
    public PoetryResult<Page> listMenstruationConfig(@RequestBody BaseRequestVO baseRequestVO) {
        menstruationConfigService.lambdaQuery()
                .orderByDesc(MenstruationConfig::getCreateTime).page(baseRequestVO);
        return PoetryResult.success(baseRequestVO);
    }

}
